<?php

namespace App\Repository\Repositories;

use App\Repository\Repositories\Interfaces\ReceivingAccountRepository;
use App\Repository\Models\ReceivingAccount;

/**
 * Class ReceivingAccountRepositoryEloquent.
 *
 * @package namespace App\Repository\Repositories;
 */
class ReceivingAccountRepositoryEloquent extends BaseRepository implements ReceivingAccountRepository
{
    /**
     * 搜索
     * @var array
     */
    protected $fieldSearchable = [
    ];

    /**
     * Specify Model class name
     *
     * @return string
     */
    public function model()
    {
        return ReceivingAccount::class;
    }

    public function query()
    {
        return $this->model->newQuery();
    }
    
    public function defaultAccount($shop_id){
        $ret = $this->findWhere(['shop_id' => $shop_id,'is_default'=>1]);
        return $ret ;
    }
    
    public function getLastId(){
        $ret = $this->orderBy("id","desc")->firstOrNew();
        return $ret ;
    }
    
    public function updateDefault($data){
         
        if($data['is_default']==1){
            $this->model->where(['shop_id' => $data['shop_id']])->update( ['is_default'=>0] );
        }
 
        return $this->model->where(['id'=>$data['id'],'shop_id' => $data['shop_id']])->update( ['is_default'=>$data['is_default']] );
    }
    
}
